<template>
    <uv-cell-group :border="false" :customStyle="{ background: '#fff', borderRadius: '0rpx' }">
        <!-- 任务名称 -->

        <uv-cell :border="true" title="任务名称" :value="formData.Name"></uv-cell>
        <!-- 任务内容 -->
        <uv-cell :border="true" title="任务内容">
            <template v-slot:label>
                <uv-textarea :customStyle="{
                    background: '#edf2fa',
                    border: 'none',
                    marginTop: '20rpx',
                }" placeholder="" height='188rpx' disabled v-model="formData.Content"></uv-textarea>
            </template>
        </uv-cell>
        <!-- 任务类型编码 -->
        <uv-cell :border="true" title="任务类型" :value="rwlx[formData.TypeCode]"></uv-cell>
        <!-- 截止时间 -->
        <uv-cell :border="true" title="截止时间" :value="formData.EndTime"></uv-cell>

        <!-- 任务指定用户 -->
        <!-- formData.ToDoUserId -->
        <uv-cell :border="true" title="指定用户" :value="zdyh.text"></uv-cell>

        <!-- 任务对象ID -->
        <uv-cell :border="true" title="任务对象统一编号" :value="formData.ObjectId"></uv-cell>
        <!-- 任务对象名称 -->
        <uv-cell :border="true" title="对象名称" :value="formData.ObjectName"></uv-cell>
        <!-- 任务对象类型 -->

        <uv-cell :border="true" title="对象类型" :value="disasterType[formData.ObjectTypeCode]"></uv-cell>
    </uv-cell-group>

</template>

<script lang="ts" setup>
import { useUserChildrenList } from '@/hooks/useOptions'
import { SysTaskLook_API } from '@/server/home'
import { useDictStore } from '@/stores'
const { childrenList, fetchUserChildrenList } = useUserChildrenList()
const dictStore = useDictStore()

const formData = ref({
    Name: '',
    Content: '',
    TypeCode: '',
    EndTime: '',
    ToDoUserId: null,
    ObjectId: '',
    ObjectName: '',
    ObjectTypeCode: ''
})

const rwlx = computed(() => {
    return dictStore.dictData['task_type']?.reduce((acc, el) => {
        acc[el.value] = el.text;
        return acc;
    }, {}) || {}
})
const zdyh = computed(() => {
    return childrenList.value.find((el) => el.value === formData.value.ToDoUserId) || {}
})
const disasterType = computed(() => {
    return dictStore.dictData['disaster_type']?.reduce((acc, el) => {
        acc[el.value] = el.text;
        return acc;
    }, {}) || {}
})
onLoad((options) => {
    //请求字典数据
    dictStore.getDictData(['disaster_type', 'task_type'])
    fetchUserChildrenList(1)
    initTask(options.id)
})
const initTask = async (id) => {
    const res = await SysTaskLook_API(id)
    if (res.IsSuccess) {
        formData.value = res.Data
        formData.value.EndTime = res.Data.EndTime.replace("T", " ")
    } else {
        uni.$uv.toast(res.Message)
    }
}
</script>

<style lang="scss" scoped></style>
